package qc.module.iot.protocol.sl651;

import com.baomidou.mybatisplus.annotation.EnumValue;
import lombok.AllArgsConstructor;
import lombok.Getter;
import org.apache.commons.lang3.StringUtils;

/**
 * SL651编码要素及标识符枚举，按照附录C 表C.1 编码要素及标识符汇总表定义
 *
 * @author QuCheng Tech
 * @since 2025/11/14
 */
@Getter
@AllArgsConstructor
public enum SL651_IdentifierEnum {
    UN_DEFINE(0, "备用"),//未定义、备用、保留
    PREFIX_TIME(0xF0, "TT"),//观测时间引导符
    PREFIX_STCD(0xf1, "ST"),//测站编码引导符
    ELEMENT_RAIN_20(0x20, "PJ"),//当前降水量
    ELEMENT_RAIN_21(0x21, "PN01"),//1min时段降水量
    ELEMENT_RAIN_22(0x22, "PN05"),//5min时段降水量
    ELEMENT_RAIN_23(0x23, "PN10"),//10min时段降水量
    ELEMENT_RAIN_24(0x24, "PN30"),//30min时段降水量
    ELEMENT_RAIN_25(0x25, "PR"),//暴雨量
    ELEMENT_RAIN_26(0x26, "PT"),//降水量累计值
    ELEMENT_Q_27(0x27, "Q"),//瞬时流量、抽水流量
    ELEMENT_V_38(0x38, "VT"),//电源电压
    ELEMENT_Z_39(0x39, "Z"),//瞬时河道水位、潮位
    ELEMENT_Z_3A(0x3A, "ZB"),//库（闸、站）下水位
    ELEMENT_Z_3B(0x3B, "ZU"),//库（闸、站）上水位
    ELEMENT_Z_3C(0x3C, "Z1"),//水位1
    ELEMENT_Z_3D(0x3D, "Z2"),//水位2
    ELEMENT_Z_3E(0x3E, "Z3"),//水位3
    ELEMENT_Z_3F(0x3F, "Z4"),//水位4
    ELEMENT_Z_40(0x40, "Z5"),//水位5
    ELEMENT_Z_41(0x41, "Z6"),//水位6
    ELEMENT_Z_42(0x42, "Z7"),//水位7
    ELEMENT_Z_43(0x43, "Z8"),//水位8
    STATUS_45(0x45, "ZT");//遥测站状态及报警信息

    @EnumValue
    private int index;
    private String name;

    @Override
    public String toString() {
        if (this != null)
            return this.name;

        return null;
    }

    /**
     * 根据int数值获取对应的枚举
     *
     * @param index 数值
     * @return qc.module.iot.protocol.sl651.SL651_IdentifierEnum
     * @author QuCheng Tech
     * @since 2025/11/14
     */
    public static SL651_IdentifierEnum getSL651_IdentifierEnum(int index) {
        if (index > 0x0) {//传入的值不限制为几个字节，不需要与0xFF做与运算
            if (index > 0x0) {
                for (SL651_IdentifierEnum item : SL651_IdentifierEnum.values()) {
                    if (item.getIndex() == index) {//判断序号使用getIndex，判断内容使用getName
                        return item;
                    }
                }
            }
        }
        return SL651_IdentifierEnum.UN_DEFINE;
    }

    /**
     * 根据int数值获取对应的枚举
     *
     * @param name 标识符Ascii码
     * @return qc.module.iot.protocol.sl651.SL651_IdentifierEnum
     * @author QuCheng Tech
     * @since 2025/11/14
     */
    public static SL651_IdentifierEnum getSL651_IdentifierEnum(String name) {
        if (StringUtils.isNotBlank(name)) {
            for (SL651_IdentifierEnum item : SL651_IdentifierEnum.values()) {
                if (StringUtils.equalsIgnoreCase(name, item.getName())) {//判断序号使用getIndex，判断内容使用getName
                    return item;
                }
            }
        }
        return SL651_IdentifierEnum.UN_DEFINE;
    }
}
